$(document).ready(function(){
    $('.submenu').hide()
    $('.product_menu > .menu > li').mouseenter(function(){
        $('.submenu').eq($(this).index()).show()
    })
    $('.product_menu > .menu > li').mouseleave(function(){
        $('.submenu').eq($(this).index()).hide()
    })
})
let curPage = 1;
let pageSize = 3;
layui.use(['laypage', 'layer'], function(){
    page()
});

function findAll(obj) {
    let result = null;
    if(obj != null){
        curPage = obj.curr;
        pageSize = obj.limit;
    }
    $.ajax({
        url: 'http://localhost:8080/product',//地址：访问后台的地址
        data: {'pageNo' : curPage,
            'pageSize': pageSize},//前端传递给后台的数据
        type: 'get',
        async: false,
        success: function (data) {//后端给前端的一个反馈
            console.log(data)
            result=data
        }
    });
    // console.log(data)
    return result.data;
}
function page(){
    layui.use(['laypage', 'layer'], function(){
        let laypage = layui.laypage
            ,layer = layui.layer;
        laypage.render({
            contentType:"application/json;charset=utf-8"
            ,elem: 'page'
            ,count: findAll().total
            ,limit:8
            ,layout: ['count', 'prev', 'page', 'next', 'refresh', 'skip']
            ,jump: function(obj){
                // console.log(findAll(obj).records)
                setList(findAll(obj).records)
            }
        });
    })
}
function setList(data)  {
    let html="";
    for (let i = 0; i < data.length; i++) {
        html += '<li>\n' +
            '                            <img src='+data[i].img+'  height="150" width="150"/>\n' +
            '                            <p><a>'+data[i].title+'</a></p>\n' +
            '                            <p><a>企业用户</a></p>\n' +
            '                            <p>\n' +
            '                                <label>市场价格:</label>\n' +
            '                                <span><a style="color: red">'+data[i].price+'</a></span>\n' +
            '                            </p>\n' +
            '   </li>';

    }
    $("#product_data").html(html);
}